<style lang="less">
@import "@/styles/table-common.less";
</style> 
<template>
  <div class="search">
    <Card>
      <Form ref="searchForm" :model="searchForm" inline :label-width="100">
        <Row v-show="openSearch" @keydown.enter.native="handleSearch">
          <FormItem label="消费用途：">
            <Select
              v-model="searchForm.orderType"
              transfer
              placeholder="请选择"
              @on-change="changeOrderType"
              style="width: 200px"
            >
              <Option value="1" label="商铺">商铺</Option>
              <Option value="2" label="培训">培训</Option>
              <Option value="3" label="会议">会议</Option>
              <Option value="4" label="场地">场地</Option>
              <Option value="5" label="活动">活动</Option>
              <Option value="6" label="储物柜">储物柜</Option>
              <Option value="7" label="角色">角色</Option>
              <Option value="9" label="打印">打印</Option>
            </Select>
          </FormItem>
          <FormItem label="日期：">
            <DatePicker
              :options="options"
              v-model="selectDate"
              type="daterange"
              format="yyyy-MM-dd"
              clearable
              @on-change="selectDateRange"
              placeholder="选择起始时间"
              style="width: 200px"
            ></DatePicker>
          </FormItem>
          <FormItem style="margin-left: -35px" class="br">
            <Button @click="handleSearch" type="primary" icon="ios-search"
              >搜索</Button
            >
            <Button @click="handleReset">重置</Button>
          </FormItem>
        </Row>
      </Form>
      <Table
        :loading="loading"
        border
        :columns="columns"
        :data="data"
        sortable="custom"
        ref="table"
      >
      </Table>
      <Row type="flex" justify="end" class="page">
        <Page
          :current="searchForm.pageNumber"
          :total="total"
          :page-size="searchForm.pageSize"
          @on-change="changePage"
          @on-page-size-change="changePageSize"
          :page-size-opts="[10, 20, 50]"
          size="small"
          show-total
          show-elevator
          show-sizer
        ></Page>
      </Row>
    </Card>
  </div>
</template>
<script>
import { getScOrderByCondition } from "@/api/index";
import { shortcuts } from "@/libs/shortcuts";
export default {
  name: "personage",
  props: ["scuid"],
  data() {
    return {
      message: "",
      height: 510,
      showUser: false,
      showType: "0",
      loading: true,
      selectDate: "",
      openSearch: true,
      idenList: [], //角色状态
      options: {
        shortcuts: shortcuts,
      },

      searchForm: {
        pageNumber: 1,
        pageSize: "10",
        sort: "createTime",
        order: "desc",
        orderType: "1",
      },
      columns: [
        {
          title: "昵称",
          key: "unickName",
          minWidth: 220,
          align: "center",
          fixed: "left",
        },
        {
          title: "手机号",
          key: "umobile",
          width: 140,
          align: "center",
          // render: (h, params) => {
          //   let nodeTxt = "";
          //   if (params.row.print) {
          //     nodeTxt = params.row.print.title;
          //   }
          //   return h("span", nodeTxt);
          // },
        },
        {
          title: "订单号",
          key: "orderNo",
          width: 140,
          align: "center",
        },
        {
          title: "订单发起时间",
          key: "createTime",
          width: 140,
          align: "center",
        },
        {
          title: "状态",
          key: "userPhone",
          width: 140,
          align: "center",
          render: (h, params) => {
            let txt = this.publicFun.orderStatus(params.row.status);
            return h("span", [txt]);
          },
        },
        {
          title: "当次消费金额",
          key: "payPrice",
          minWidth: 220,
          align: "center",
        },
        {
          title: "个人积分",
          key: "totalPrice",
          minWidth: 220,
          align: "center",
          render(h, params) {
            let nodeTxt = "";
            if (params.row.useIntegralType == "1") {
              nodeTxt = params.row.useIntegralType;
            }
            return h("span", nodeTxt);
          },
        },
        {
          title: "打印专项",
          key: "createTime",
          minWidth: 220,
          align: "center",
          render(h, params) {
            let nodeTxt = "";
            if (params.row.useIntegralType == "2") {
              nodeTxt = params.row.useIntegralType;
            }
            return h("span", nodeTxt);
          },
        },
        {
          title: "会议专项",
          key: "createTime",
          minWidth: 220,
          align: "center",
          render(h, params) {
            let nodeTxt = "";
            if (params.row.useIntegralType == "3") {
              nodeTxt = params.row.useIntegralType;
            }
            return h("span", nodeTxt);
          },
        },
        {
          title: "消费时间",
          key: "createTime",
          minWidth: 220,
          align: "center",
        },
        {
          title: "消费用途",
          key: "",
          minWidth: 220,
          align: "center",
          render(h, params) {
            let nodeTxt = "";
            if (params.row.orderType == "1") {
              nodeTxt = params.row.companyName;
            } else {
              nodeTxt = params.row.orderDetails[0].productName;
            }
            return h("span", nodeTxt);
          },
        },
      ],
      data: [],
    };
  },
  methods: {
    init() {
      this.getDataList();
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
      if (e.order == "normal") {
        this.searchForm.order = "";
      }
      this.getDataList();
    },
    getDataList() {
      this.loading = true;
      // this.searchForm.scuid = this.scuid;
      getScOrderByCondition({ ...this.searchForm, uid: this.scuid }).then(
        (res) => {
          this.loading = false;
          if (res.success) {
            this.data = res.result.content;
            this.total = res.result.totalElements;
            this.statistic = res.result.statistic;
            if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
              this.searchForm.pageNumber -= 1;
              this.getDataList();
            }
          }
        }
      );
    },

    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    changePageSize(v) {
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    selectDateRange(v) {
      if (v) {
        this.searchForm.startDate = v[0];
        this.searchForm.endDate = v[1];
      }
    },
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getDataList();
    },
    handleReset() {
      this.selectDate = "";
      this.searchForm.startDate = "";
      this.searchForm.endDate = "";
      this.searchForm.orderType = "1";
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      // 重新加载数据
      this.getDataList();
    },
    changeOrderType(e) {
      this.searchForm.startDate = "";
      this.searchForm.endDate = "";
      this.searchForm.orderType = e;
      // this.searchForm.companyName = "";
      this.getDataList();
    },
  },
  created() {},
  activated() {
    this.init();
  },
  mounted() {
    // 计算高度
    this.height = Number(document.documentElement.clientHeight - 230);
    this.init();
  },
};
</script>